# -*- coding:utf-8 -*-
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def FindKthToTail(self, head, k):
        # write code here
        # res = head
        # length = 0
        # while res:
        #     length += 1
        #     res = res.next
        # loc = length - k
        # res = head
        # if loc < 0:
        #     return None
        # for _ in range(loc):
        #     res = res.next
        # return res
        '''
        该方法是让快的先走k个当快的到最后一个点之后（不为None的点），那么慢的刚好在k的位置上
        :param head:
        :param k:
        :return:
        '''
        if k <= 0 or head == None:
            return None
        fast = head
        slow = head
        while k > 1:
            if fast.next != None:
                fast = fast.next
                k -= 1
            else:
                return None

        while fast.next != None:
            fast = fast.next
            slow = slow.next
        return slow
